package com.example.howard.xiao7music.presenter;

import android.content.Context;

import com.example.howard.xiao7music.model.GetLocalSource;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Howard on 2016/9/26.
 */
public class LocalSongPresenter {
    private GetLocalSource getLocalSource=new GetLocalSource();

    public List<Map<String, Object>> getLocalAllSonglist (Context context){

        List<Map<String, Object>> allSongList=new ArrayList<>();
        List<Map<String, Object>> list;
        Map<String, Object> map=new HashMap<>();
        String songname,singername,url,logopath,songid;
        list=getLocalSource.getAllLocalSource(context);

        for (int i=0;i<list.size();i++){
            map=new HashMap<>();
            songname=list.get(i).get("TITLE").toString();
            map.put("SONG",songname);
            singername=list.get(i).get("SINGER").toString();
            map.put("SINGER",singername);
            url=list.get(i).get("URL").toString();
            map.put("URL",url);
            logopath=null;
            map.put("LOGO",logopath);
            songid=null;
            map.put("ID",songid);
            allSongList.add(map);
        }
        return allSongList;
    }

    public List<String> getSingerlist (Context context){
        List<String> singerNameList;
        singerNameList=getLocalSource.getSingerName(context);
        return singerNameList;
    }

    public List<Map<String, Object>> getFolderlist (Context context){
        List<Map<String, Object>> folderList;
        folderList=getLocalSource.getFolderName(context);
        return folderList;
    }

    public List<Map<String, Object>> getSongListBySinger (Context context,String singer){
        List<Map<String, Object>> songList=new ArrayList<>();
        List<Map<String, Object>> list;
        Map<String, Object> map=new HashMap<>();
        String songname,singername,url,logopath,songid;

        list=getLocalSource.getLocalSourceBySinger(context,singer);

        for (int i=0;i<list.size();i++){
            map=new HashMap<>();
            songname=list.get(i).get("TITLE").toString();
            map.put("SONG",songname);
            singername=list.get(i).get("SINGER").toString();
            map.put("SINGER",singername);
            url=list.get(i).get("URL").toString();
            map.put("URL",url);
            logopath=null;
            map.put("LOGO",logopath);
            songid=null;
            map.put("ID",songid);
            songList.add(map);
        }
        return songList;
    }

    public List<Map<String, Object>> getSongListByFolder(Context context,String path){
        List<Map<String, Object>> songList=new ArrayList<>();
        List<Map<String, Object>> list;
        Map<String, Object> map=new HashMap<>();
        String songname,singername,url,logopath,songid;

        list=getLocalSource.getLocalSourceByFolder(context,path);

        for (int i=0;i<list.size();i++){
            map=new HashMap<>();
            songname=list.get(i).get("TITLE").toString();
            map.put("SONG",songname);
            singername=list.get(i).get("SINGER").toString();
            map.put("SINGER",singername);
            url=list.get(i).get("URL").toString();
            map.put("URL",url);
            logopath=null;
            map.put("LOGO",logopath);
            songid=null;
            map.put("ID",songid);
            songList.add(map);
        }
        return songList;
    }

}
